package com.itheima.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class StudentDemo {
    
    //传递多个查询条件
    // public static Student getStudentInfo(List<Student> studentList,String value,String flag){
    //
    //     for (Student student : studentList) {
    //
    //         if ("name".equals(flag)){
    //             if (value.equals(student.getName())){
    //                 return student;
    //             }
    //         }
    //
    //         if ("sex".equals(flag)){
    //             if (value.equals(student.getSex())){
    //                 return student;
    //             }
    //         }
    //
    //     }
    //
    //     return null;
    // }
    
    public static void main(String[] args) {
        
        List<Student> students = new ArrayList<>();
        students.add(new Student(1, "张三", "M"));
        students.add(new Student(2, "李四", "M"));
        students.add(new Student(3, "王五", "M"));
        StudentService service = new StudentService() {
            @Override
            public Student getStudentInfo(List<Student> studentList, Student student) {
                for (Student s : studentList) {
                    if (s.getName().equals(student.getName())) {
                        return s;
                    }
                }
                return null;
            }
        };
        Student student = new Student();
        student.setName("张三");
        Student info = service.getStudentInfo(students, student);
        //
        System.out.println(info);
        
        // 
        StudentService service1=((studentList, student1) -> {
            for (Student s : studentList) {
                if (s.getSex().equals(student1.getSex())) {
                    return s;
                }
            }
            return null;
        });
        student.setSex("M");
        Student info1 = service1.getStudentInfo(students, student);
        System.out.println(info1);
        // Predicate<? super Student> predicate;
        // Student zhangsan1 = students.stream()
        //         .filter((s) -> "张三".equals(s.getName()))
        //         .collect(Collectors.toList()).get(0);
        //
        // Student sex1 = students.stream()
        //         .filter(s -> "M".equals(s.getSex()))
        //         .collect(Collectors.toList()).get(0);
        // System.out.println(zhangsan1);
        // System.out.println(sex1);
        // Student studentInfo = getStudentInfo(students, "张三", "name");
        // Student studentInfo1 = getStudentInfo(students, "M", "sex");
    }
}
